package com.example.demo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.entity.BeautyCare;
import com.example.demo.entity.VO.BeautyCareVO;
import com.example.demo.result.Result;
import com.example.demo.service.IBeautyCareService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 美容护理表 前端控制器
 * </p>
 *
 * @author Mr.wyy
 * @since 2024-06-03
 */
@Api(tags = "美容护理接口")
@RestController
@RequestMapping("/beauty-care")
public class BeautyCareController {

    @Resource
    private IBeautyCareService beautyCareService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "查询美容护理表所有数据")
    @GetMapping("/findAllBeautyCare")
    public Result<List<BeautyCare>> findAll() {
        //查询所有的美容护理数据
        BeautyCare beautyCare = new BeautyCare();
        List<BeautyCare> beautyCareList = beautyCareService.selectBeautyCareAll();
        beautyCareList.add(beautyCare);
        return Result.success(beautyCareList).msg("查询成功");
    }

    /**
     * 根据id查询美容护理数据
     * @param id
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "根据id查询数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "组件id",required = true)
    })
    @GetMapping("/selectBeautyCareByBcId")
    public Result<BeautyCare> selectBeautyCareByBcId(@RequestParam Integer id) {
        return Result.success(beautyCareService.selectBeautyCareByBcId(id)).msg("查询成功");
    }

    /**
    * 添加
    * @param
    * @return
    */
    @ApiOperationSupport(author = "Mr.sdy")
    @ApiOperation(value = "添加美容护理信息")
    @PostMapping("/add")
    public Result<String> add(BeautyCareVO beautyCareVO) {
        BeautyCare beutyCare = new BeautyCare();
        BeanUtil.copyProperties(beautyCareVO,beutyCare);
        if(!beautyCareService.addBeautyCare(beutyCare)){
            return Result.error().msg("添加失败");
        }
        return Result.success().msg("添加成功");
    }


    /**
     * 删除接口
     * @param id
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "删除接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "组件id",required = true)
    })
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable Integer id) {
        return Result.success(beautyCareService.deleteBeautyCareById(id)).msg("删除成功");
    }

}